#!/usr/bin/python3
# learn to write a web spider
# get information of

import smtplib
from email.mime.text import MIMEText
from email.header import Header

def send_email():
    
    mail_host='smtp.163.com'  #SET server
    mail_user='custipen@163.com'   
    mail_pass='custipen1'       
    
    sender = 'custipen@163.com'
    receivers = ['yuanzhuoma@pku.edu.cn']  
    message = MIMEText('Energency! Check the Power of UPS!!!', 'plain', 'utf-8')
    message['From'] = 'custipen@163.com'
    message['To'] = 'yuanzhuoma@pku.edu.cn'

    subject = 'Emergency! UPS'
    message['Subject'] = Header(subject, 'utf-8')
    
    try:
        smtpObj = smtplib.SMTP()
        smtpObj.connect(mail_host, 25)
        smtpObj.login(mail_user,mail_pass)
        smtpObj.sendmail(sender, receivers, message.as_string())
        print ("Success sending email")
    except smtplib.SMTPException:
        print ("Error: can`t send email")
        
send_email()
